﻿@using System.Web.UI.WebControls
@using CMSMVC4.MultiResource
@model CMSMVC4.Category
@{
    ViewBag.Title = @Admin.AddEquipment;
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<div class="row-fluid">
    <div class="span7" style="width: 100%">
        <div class="box paint color_4">
            <div class="title">
                <h4>
                    <span>@Admin.AddNews</span>
                </h4>
            </div>
            <div class="content">
                @if (Model != null)
                {
                    using (Ajax.BeginForm("Them", "ThietBi", null, new AjaxOptions() {HttpMethod = "Post" ,OnBegin = "begin()", OnSuccess="end(data)" }, new { @id = "form", name = "form" }))
                    {
                    <div class="form-row control-group row-fluid">
                        <span id="mess">@ViewBag.mess</span>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3">Chọn danh mục <span class="help-block">Chọn danh mục</span>
                        </label>
                        <div class="controls span7">
                            @{ Html.RenderAction("DanhSachDanhMuc", "ThietBi", new { id = Model.paren }); }
                        </div>
                    </div>
                               Html.RenderAction("GetNameCate", "ThietBi", new { id = Model.Id });
                    <div id="load_tab">
                        @{Html.RenderAction("listTab", "ThietBi", new { id = Model.Id });}
                    </div>
                    <input name="idcate" type="hidden" value="@Model.Id" />
                    <input class="btn btn-danger btn-large" type="submit" value="@Admin.Submit" />
                    <input class="btn btn-danger btn-large" onclick="newtab(@Model.Id)" type="button" value="@Admin.NewTab" />
                    @*<a data-ajax="true" data-ajax-method="Get" data-ajax-mode="replace" data-ajax-update="#load_tab" data-ajax-begin="luu()" data-ajax-success="loadlisttab()" href="@Url.Action("NewTab", "ThietBi", new { id = Model.Id })">
                        
                    </a>*@
                    }
                }
            </div>
        </div>
    </div>
</div>
<script language ="javascript" type="text/javascript">
    function newtab(ma) {
        //load lai ckediter
        for (var i in CKEDITOR.instances) {
            CKEDITOR.instances[i].updateElement();
        }
        //-----------------
        $('#loading').fadeIn();
        $.ajax({
            type: "Post",
            dataType: "json",
            url: "/Admin/ThietBi/them",
            data: $('#form').serialize(),
            success: function (data) {
                $('#mess').text(data);
                $.ajax({
                    type: "Get",
                    dataType: "html",
                    url: "/Admin/ThietBi/NewTab",
                    data: { id: ma },
                    success: function (data2) {
                        $('#load_tab').html(data2);
                        loadlisttab();
                        $('#loading').fadeOut();
                    }
                });
            }
        });
    }
    function xoatab(ma) {
        var con = confirm('are you sure?');
        if (con == true) {
            //load lai ckediter
            for (var i in CKEDITOR.instances) {
                CKEDITOR.instances[i].updateElement();
            }
            //-----------------
            $('#loading').fadeIn();
            $.ajax({
                type: "Post",
                dataType: "json",
                url: "/Admin/ThietBi/them",
                data: $('#form').serialize(),
                success: function (data) {
                    $('#mess').text(data);
                    $.ajax({
                        type: "Post",
                        dataType: "html",
                        url: "/Admin/ThietBi/XoaTab",
                        data: { id: ma },
                        success: function (data2) {
                            $('#load_tab').html(data2);
                            loadlisttab();
                            $('#loading').fadeOut();
                        }
                    });
                }
            });
        }
    }
    function luu() {
        //-----------------
        $('#loading').fadeIn();
        $.ajax({
            type: "Post",
            dataType: "json",
            url: "/Admin/ThietBi/them",
            data: $('#form').serialize(),
            success: function (data) {
                $('#mess').fadeIn(0);
                $('#mess').text(data);
                $('#loading').fadeOut();
                $('#mess').delay(5000).fadeOut(1000);
            }
        });
    }
    function begin() {
        $('#loading').fadeIn();
    }
    function end(data) {
        $('#mess').fadeIn(0);
        $('#mess').text(data);
        $('#loading').fadeOut();
        $('#mess').delay(5000).fadeOut(1000);
    }
    $(function () {
        var saved = setInterval("luu()", 180000);
    });
</script>